#ifndef TOOLS
#define TOOLS
#include <thread>
#include <iostream>
#include <mutex>
#include <list>
extern "C"
{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/rational.h>
}

namespace lcf
{
    void MSleep(unsigned int ms);

    // 获取当前时间戳 毫秒
    long long NowMs();

    void XFreeFrame(AVFrame **frame);

    void PrintErr(int err);

    // 根据时间基数计算
    long long XRescale(long long pts,
                       AVRational *src_time_base,
                       AVRational *des_time_base);

    // 日志级别 DEBUG INFO ERROR FATAL
    enum XLogLevel
    {
        XLOG_TYPE_DEBUG,
        XLOG_TYPE_INFO,
        XLOG_TPYE_ERROR,
        XLOG_TYPE_FATAL
    };
#define LOG_MIN_LEVEL XLOG_TYPE_DEBUG
#define XLOG(s, level)                                                    \
    if (level >= LOG_MIN_LEVEL)                                           \
        std::cout << level << ":" << __FILE__ << ":" << __LINE__ << ":\n" \
                  << s << std::endl;
#define LOGDEBUG(s) XLOG(s, XLOG_TYPE_DEBUG)
#define LOGINFO(s) XLOG(s, XLOG_TYPE_INFO)
#define LOGERROR(s) XLOG(s, XLOG_TPYE_ERROR)
#define LOGFATAL(s) XLOG(s, XLOG_TYPE_FATAL)
}

#endif